#include "objcommon.h"
#include <string.h>
#include <stdio.h>

ObjCommon::ObjCommon(char* n)
{
	level = 1;
	initName(n);
}

ObjCommon::~ObjCommon()
{

}

void ObjCommon::initName(char* n)
{
	memset(name,0,sizeof(name));
	memcpy(name,n,strlen(n));
}

void ObjCommon::levelUp()
{
	if(level == MAX_LEVEL)
		return;

	level ++;
	update();
}

void ObjCommon::levelUp(unsigned int grow)
{
	level = (level + grow) > MAX_LEVEL ?  MAX_LEVEL : level + grow;
	update();
}

void ObjCommon::levelUpto(unsigned int l)
{
	if( l > MAX_LEVEL )
		return;

	level = l;
	update();
}

void ObjCommon::showValsInfo()
{
	printf("name:%s, level:%d, hp:%d, mp:%d, a:%d, m:%d, ad:%d, md:%d\n",
		name,level,
		health.m_hp,health.m_mp,fight.m_attack,fight.m_magic,
		defence.m_attackDefence,defence.m_magicDefence);
}